package com.jta.test;

import com.jta.beans.HisTest;
import com.jta.beans.TmsTest;
import com.jta.service.intf.IBaseService;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;


public class JtaTestService {
    private static IBaseService service;
    static TmsTest tmsTest;
    static HisTest hisTest;

    @BeforeClass
    public static void init(){
        ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContextJTA_test.xml"});
        BeanFactory factory = (BeanFactory) context;
        service = factory.getBean("baseServiceImpl",IBaseService.class);

        tmsTest = new TmsTest();
        tmsTest.setName("张三1");
        hisTest = new HisTest();
        hisTest.setName("李四1");
    }


    @Test
    public void testDataSource() {
        try {
            @SuppressWarnings("unchecked")
            List<TmsTest> tmsList = service.findTms();
            //.out.println("tms============" + tmsList.get(0).getName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            @SuppressWarnings("unchecked")
            List<HisTest> hisList = service.findHis();
            //.out.println("his=================" + hisList.get(0).getName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            service.save(tmsTest, hisTest);
        } catch (Exception e) {
            //.out.println("保存操作失败,事务整体回滚。");
        }

    }
}
